import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:permission_handler/permission_handler.dart';

class ScanPage extends StatelessWidget {
  const ScanPage({super.key});

  @override
  Widget build(BuildContext context) {
    _requestCameraPermission(); // 请求相机权限
    return Scaffold(
      appBar: AppBar(title: const Text('扫一扫')),
      body: QRView(
        key: GlobalKey(debugLabel: 'QR'),
        onQRViewCreated: (QRViewController controller) {},
      ),
    );
  }

  Future<void> _requestCameraPermission() async {
    // 添加请求权限的方法
    final status = await Permission.camera.request();
    if (status.isDenied) {
      // 权限被拒绝，处理相应逻辑
    }
  }
}
